package Test;

public class DemoB {
    public static void main(String[] args) {
        try {
            System.out.println("我们一起区图书馆...");
            for (int i = 1; i < 6; i++) {
                new Thread(new 图书馆(i)).start();
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            System.out.println(e.getMessage()+"1");;
        }
    }

}
class 图书馆 extends Thread{
    private Integer num;

    public 图书馆(Integer num) {
        super();
        this.num = num;
    }
    public void run() {

        a(num);

    }
    public synchronized void a(int num){
        if(num==1||num==2||num==3||num==4){
            System.out.println("还有人作业没写玩呢，我们等等吧");
            try {
                wait();
            } catch (InterruptedException e) {
                System.out.println(e.getMessage()+"2");;
            }
        }else{
            System.out.println("他来了");
            notifyAll();
        }
        System.out.println("我们走吧....");
    }

}
